package com.wuzao.leetcodeTest;

import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int bagweight = scanner.nextInt();

        int[] weight = new int[n];
        int[] value = new int[n];

        for (int i = 0; i < n; ++i) {
            weight[i] = scanner.nextInt();
        }
        for (int j = 0; j < n; ++j) {
            value[j] = scanner.nextInt();
        }

        // dp 数组
        int[][] dp = new int[n][bagweight+1];

        for (int i = 0; i < n; i ++){
            for (int j = 0; j < bagweight+1; j ++){
                if (i==0){
                    dp[i][j] = 0;
                    continue;
                }
                // 第 0 个物品
                else if (j < weight[i]) {
                    dp[i][j] = dp[i - 1][j];
                    continue;
                }
                dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-weight[i]]+value[i]);
            }
        }
        System.out.println(dp[n - 1][bagweight]);

    }
}
